﻿namespace Holoville.HOTween.Core.Easing
{
    using System;

    public static class Elastic
    {
        private const float TwoPi = 6.283185f;

        public static float EaseIn(float time, float startValue, float changeValue, float duration)
        {
            return EaseIn(time, startValue, changeValue, duration, 0f, 0f);
        }

        public static float EaseIn(float time, float startValue, float changeValue, float duration, float amplitude, float period)
        {
            float num;
            if (time == 0f)
            {
                return startValue;
            }
            if ((time /= duration) == 1f)
            {
                return (startValue + changeValue);
            }
            if (period == 0f)
            {
                period = duration * 0.3f;
            }
            if (((amplitude == 0f) || ((changeValue > 0f) && (amplitude < changeValue))) || ((changeValue < 0f) && (amplitude < -changeValue)))
            {
                amplitude = changeValue;
                num = period / 4f;
            }
            else
            {
                num = (period / 6.283185f) * ((float) Math.Asin((double) (changeValue / amplitude)));
            }
            return (-((amplitude * ((float) Math.Pow(2.0, (double) (10f * --time)))) * ((float) Math.Sin((double) ((((time * duration) - num) * 6.283185f) / period)))) + startValue);
        }

        public static float EaseInOut(float time, float startValue, float changeValue, float duration)
        {
            return EaseInOut(time, startValue, changeValue, duration, 0f, 0f);
        }

        public static float EaseInOut(float time, float startValue, float changeValue, float duration, float amplitude, float period)
        {
            float num;
            if (time == 0f)
            {
                return startValue;
            }
            if ((time /= (duration * 0.5f)) == 2f)
            {
                return (startValue + changeValue);
            }
            if (period == 0f)
            {
                period = duration * 0.45f;
            }
            if (((amplitude == 0f) || ((changeValue > 0f) && (amplitude < changeValue))) || ((changeValue < 0f) && (amplitude < -changeValue)))
            {
                amplitude = changeValue;
                num = period / 4f;
            }
            else
            {
                num = (period / 6.283185f) * ((float) Math.Asin((double) (changeValue / amplitude)));
            }
            if (time < 1f)
            {
                return ((-0.5f * ((amplitude * ((float) Math.Pow(2.0, (double) (10f * --time)))) * ((float) Math.Sin((double) ((((time * duration) - num) * 6.283185f) / period))))) + startValue);
            }
            return (((((amplitude * ((float) Math.Pow(2.0, (double) (-10f * --time)))) * ((float) Math.Sin((double) ((((time * duration) - num) * 6.283185f) / period)))) * 0.5f) + changeValue) + startValue);
        }

        public static float EaseOut(float time, float startValue, float changeValue, float duration)
        {
            return EaseOut(time, startValue, changeValue, duration, 0f, 0f);
        }

        public static float EaseOut(float time, float startValue, float changeValue, float duration, float amplitude, float period)
        {
            float num;
            if (time == 0f)
            {
                return startValue;
            }
            if ((time /= duration) == 1f)
            {
                return (startValue + changeValue);
            }
            if (period == 0f)
            {
                period = duration * 0.3f;
            }
            if (((amplitude == 0f) || ((changeValue > 0f) && (amplitude < changeValue))) || ((changeValue < 0f) && (amplitude < -changeValue)))
            {
                amplitude = changeValue;
                num = period / 4f;
            }
            else
            {
                num = (period / 6.283185f) * ((float) Math.Asin((double) (changeValue / amplitude)));
            }
            return ((((amplitude * ((float) Math.Pow(2.0, (double) (-10f * time)))) * ((float) Math.Sin((double) ((((time * duration) - num) * 6.283185f) / period)))) + changeValue) + startValue);
        }
    }
}

